<template>
  <div class="mobile-container">
    <!-- header部分 -->
    <header class="mobile-header">
      <p>确认订单</p>
    </header>

    <!-- 配送地址区域 -->
    <div class="delivery-address">
      <div class="delivery-header">
        <i class="fa fa-map-marker text-4vw mr-2vw"></i>
        <span class="text-3.5vw">订单配送至</span>
      </div>
      <div class="delivery-content">
        <div class="address-main">
          <p class="address-text">{{ deliveryAddress.address }}</p>
          <i class="fa fa-angle-right text-5vw"></i>
        </div>
        <p class="contact-info">{{ deliveryAddress.contactName }} {{ deliveryAddress.contactPhone }}</p>
      </div>
    </div>

    <!-- 商家信息区域 -->
    <div class="business-section">
      <div class="business-header">
        <i class="fa fa-store text-4vw mr-2vw text-primary"></i>
        <h3 class="business-name">{{ business.name || '万家饺子（驼峰街店）' }}</h3>
      </div>
    </div>

    <!-- 订单明细区域 -->
    <div class="order-details" v-if="cartItems && cartItems.length > 0">
      <div class="section-header">
        <span class="section-title">订单明细</span>
      </div>
      <div class="items-list">
        <div v-for="item in cartItems" :key="item.id" class="order-item">
          <div class="item-info">
            <img :src="item.img" :alt="item.name" class="item-image">
            <div class="item-details">
              <p class="item-name">{{ item.name }}</p>
              <p class="item-quantity">x {{ item.quantity }}</p>
            </div>
          </div>
          <p class="item-price">￥{{ (item.price * item.quantity).toFixed(2) }}</p>
        </div>
      </div>

      <!-- 费用明细 -->
      <div class="fee-details">
        <div class="fee-item">
          <span class="fee-label">商品总额</span>
          <span class="fee-value">￥{{ (finalPrice - (business.deliveryFee || 3)).toFixed(2) }}</span>
        </div>
        <div class="fee-item">
          <span class="fee-label">配送费</span>
          <span class="fee-value">￥{{ business.deliveryFee || 3 }}</span>
        </div>
        <div class="fee-item total-fee">
          <span class="fee-label">合计</span>
          <span class="fee-value total-price">￥{{ finalPrice || 18 }}</span>
        </div>
      </div>
    </div>
    
    <!-- 购物车为空时的提示 -->
    <div v-else class="empty-cart">
      <i class="fa fa-shopping-cart empty-icon"></i>
      <p class="empty-title">购物车为空</p>
      <p class="empty-subtitle">请先选择商品</p>
      <button @click="$router.push('/index')" class="empty-button">
        去选购
      </button>
    </div>

    <!-- 底部间距 -->
    <div class="bottom-spacing"></div>

    <!-- 底部支付按钮 -->
    <div class="payment-bar">
      <div class="price-summary">
        <div class="total-amount">
          <span class="currency">￥</span>
          <span class="amount">{{ finalPrice || 18 }}</span>
        </div>
        <p class="price-note">含配送费</p>
      </div>
      <button @click="goToPayment" class="pay-button">
        去支付
      </button>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useOrder } from '../composables/useOrder'

export default defineComponent({
  name: 'Order',
  setup() {
    const router = useRouter()
    const { cartItems, business, finalPrice } = useOrder()

    // 默认配送地址
    const deliveryAddress = computed(() => ({
      address: '云南大学呈贡校区楸苑一栋宿舍楼下',
      contactName: '向日葵女士',
      contactPhone: '18008746522'
    }))

    const goToPayment = () => {
      router.push('/payment')
    }

    return {
      deliveryAddress,
      cartItems,
      business,
      finalPrice,
      goToPayment
    }
  }
})
</script>

<style scoped>
/* 总容器 */
.mobile-container {
  width: 100%;
  min-height: 100vh;
  background-color: #f5f5f5;
  padding-bottom: 16vw;
}

/* 配送地址区域 */
.delivery-address {
  background: linear-gradient(135deg, #0097FF 0%, #00B4FF 100%);
  padding: 4vw;
  margin-top: 12vw;
  color: white;
}

.delivery-header {
  display: flex;
  align-items: center;
  margin-bottom: 3vw;
  opacity: 0.9;
}

.delivery-content {
  padding-left: 6vw;
}

.address-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2vw;
}

.address-text {
  font-size: 4.5vw;
  font-weight: 600;
  flex: 1;
  line-height: 1.4;
}

.contact-info {
  font-size: 3.2vw;
  opacity: 0.8;
}

/* 商家信息区域 */
.business-section {
  background: white;
  padding: 4vw;
  margin-top: 2vw;
  border-radius: 2vw 2vw 0 0;
}

.business-header {
  display: flex;
  align-items: center;
}

.business-name {
  font-size: 4.2vw;
  font-weight: 600;
  color: #333;
  margin: 0;
}

/* 订单明细区域 */
.order-details {
  background: white;
  margin-top: 0.5vw;
}

.section-header {
  padding: 4vw 4vw 2vw 4vw;
  border-bottom: 1px solid #f0f0f0;
}

.section-title {
  font-size: 4vw;
  font-weight: 600;
  color: #333;
}

.items-list {
  padding: 0 4vw;
}

.order-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4vw 0;
  border-bottom: 1px solid #f8f8f8;
}

.order-item:last-child {
  border-bottom: none;
}

.item-info {
  display: flex;
  align-items: center;
  flex: 1;
}

.item-image {
  width: 12vw;
  height: 12vw;
  border-radius: 2vw;
  object-fit: cover;
  margin-right: 3vw;
}

.item-details {
  flex: 1;
}

.item-name {
  font-size: 3.8vw;
  color: #333;
  margin: 0 0 1vw 0;
  line-height: 1.3;
}

.item-quantity {
  font-size: 3.2vw;
  color: #999;
  margin: 0;
}

.item-price {
  font-size: 4vw;
  font-weight: 600;
  color: #333;
  margin: 0;
}

/* 费用明细 */
.fee-details {
  background: #fafafa;
  padding: 4vw;
  margin-top: 2vw;
}

.fee-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2vw 0;
}

.fee-item.total-fee {
  border-top: 1px solid #e0e0e0;
  padding-top: 3vw;
  margin-top: 2vw;
}

.fee-label {
  font-size: 3.5vw;
  color: #666;
}

.fee-value {
  font-size: 3.5vw;
  color: #333;
}

.total-fee .fee-label,
.total-fee .fee-value {
  font-weight: 600;
  font-size: 4vw;
}

.total-price {
  color: #ff6b35;
}

/* 空购物车样式 */
.empty-cart {
  background: white;
  padding: 12vw 4vw;
  text-align: center;
  margin-top: 2vw;
}

.empty-icon {
  font-size: 16vw;
  color: #ddd;
  margin-bottom: 4vw;
}

.empty-title {
  font-size: 4.5vw;
  color: #666;
  margin: 0 0 2vw 0;
}

.empty-subtitle {
  font-size: 3.5vw;
  color: #999;
  margin: 0 0 6vw 0;
}

.empty-button {
  background: #0097FF;
  color: white;
  border: none;
  border-radius: 6vw;
  padding: 3vw 8vw;
  font-size: 3.8vw;
  font-weight: 600;
  cursor: pointer;
}

/* 底部间距 */
.bottom-spacing {
  height: 18vw;
}

/* 底部支付栏 */
.payment-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  display: flex;
  align-items: center;
  padding: 3vw 4vw;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
}

.price-summary {
  flex: 1;
  margin-right: 4vw;
}

.total-amount {
  display: flex;
  align-items: baseline;
  margin-bottom: 0.5vw;
}

.currency {
  font-size: 3.5vw;
  color: #333;
  font-weight: 600;
}

.amount {
  font-size: 5.5vw;
  color: #333;
  font-weight: 700;
  margin-left: 0.5vw;
}

.price-note {
  font-size: 2.8vw;
  color: #999;
  margin: 0;
}

.pay-button {
  background: linear-gradient(135deg, #38CA73 0%, #2db55d 100%);
  color: white;
  border: none;
  border-radius: 8vw;
  padding: 4vw 8vw;
  font-size: 4.2vw;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(56, 202, 115, 0.3);
  transition: all 0.3s ease;
}

.pay-button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 4px rgba(56, 202, 115, 0.3);
}
</style>

 